# Contributor: omni <omni+alpine@hack.org>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ruby-sdbm
_gemname=sdbm
pkgver=1.0.0
pkgrel=3
pkgdesc="Simple file-based key-value store with String keys and values for Ruby"
url="https://github.com/ruby/sdbm"
arch="all"
license="BSD-2-Clause"
checkdepends="ruby-test-unit"
makedepends="ruby-dev ruby-rdoc"
subpackages="$pkgname-doc"
source="https://github.com/ruby/sdbm/archive/v$pkgver/ruby-sdbm-$pkgver.tar.gz"
builddir="$srcdir/$_gemname-$pkgver"

prepare() {
	default_prepare
	sed -i '/require .bundler/d' Rakefile
}

build() {
	gem build $_gemname.gemspec

	gem install \
		--local \
		--install-dir dist \
		--ignore-dependencies \
		--document ri \
		--verbose \
		$_gemname

	# Remove duplicated files (sdbm.so is loaded from extensions directory).
	rm -f dist/gems/$_gemname-*/lib/*.so
	rm -rf dist/gems/$_gemname-*/ext
}

check() {
	GEM_PATH='./dist' ruby -Itests -e "Dir.glob('./test/**/test_*.rb', &method(:require))"
}

package() {
	local gemdir="$pkgdir/$(ruby -e 'puts Gem.default_dir')"

	cd "$builddir"/dist

	mkdir -p "$gemdir"
	cp -r doc extensions gems specifications "$gemdir"/
}

doc() {
	pkgdesc="$pkgdesc (ri docs)"

	amove "$(ruby -e 'puts Gem.default_dir')"/doc
}

sha512sums="db4f3efa9ba72d554437d1b5190e29f724d780d343f0c12f8fd4bfd0493bf4646831164711ed6a2b348b2281be9f666ffcb15cd9b7b9c4ff2046af34bc0d2c16  ruby-sdbm-1.0.0.tar.gz"
